<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <!-- 查询区域-END -->
    <!-- table区域-begin -->
    <a-row>
      <a-col :span="8">
        <template>
          <a-timeline mode="alternate">
            <a-timeline-item :key="index" v-for="(item, index) in dataSource">
              <a-icon slot="dot" :color="circleColors[index]" type="check-circle" style="font-size: 16px" />
              <p style="font-size: 16px">
                <span :style="{ background: circleColors[index] }"
                  >{{ item.business_dictText }} 数量 {{ item.quantity }}</span
                >
              </p>
              <p style="font-size: 16px">{{ item.operationTime }}</p>
            </a-timeline-item>
          </a-timeline>
        </template>
        <a-form-model-item label="入库单编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="code">
          {{ code }}
        </a-form-model-item>
        <a-form-model-item label="库存数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="quantity">
          {{ quantity }}
        </a-form-model-item></a-col
      >
      <a-col :span="16">
        <div>
          <a-table
            ref="table"
            size="middle"
            bordered
            rowKey="id"
            class="j-table-force-nowrap1"
            :scroll="{ x: true }"
            :columns="columns"
            :dataSource="dataSource"
            :pagination="ipagination"
            :loading="loading"
            :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
            @change="handleTableChange"
          />
        </div>
      </a-col>
    </a-row>
  </a-card>
</template>
<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { getAction, putAction } from '@api/manage'
import { filterMultiDictText } from '@/components/dict/JDictSelectUtil'
import { forEach } from 'min-dash'

export default {
  name: 'BussInOutDetailListForm',
  mixins: [JeecgListMixin, mixinDevice],
  components: {},
  // props: ['category', "modalWidth",],
  props: {
    detailId: {
      type: String,
      require:false
    },
    category: {
      type: String,
    },
    modalWidth: {
      type: Number,
      required: false,
      default: 1250,
    },
    checkval: {
      type: String,
      default: 'radio',
    },
    supplierId: {
      type: String,
      required: false,
    },
    code: {
      type: String,
    },
    quantity: {
      type: String,
    },
  },
  watch: {
    detailId(newValue) {
      // 当category变更时，可以进行一些处理
      console.log('详情Category changed to:', newValue)
      this.queryParam = { id: newValue }
      this.loadData()
    },
        code(newValue) {
      // 当category变更时，可以进行一些处理
      console.log('Category changed to2:', newValue)
      this.code = newValue
    },
    quantity(newValue) {
      // 当category变更时，可以进行一些处理
      console.log('Category changed to3:', newValue)
      this.quantity = newValue
    },
  },
  data() {
    return {
      description: '库存明细页面',
      circleColors: [],
      visible: false,
      title: '库存明细',
      disableMixinCreated: true,
      queryParam: { id: this.category | 1 },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '操作人',
          align: 'center',
          dataIndex: 'operator',
        },
        {
          title: '操作时间',
          align: 'center',
          dataIndex: 'operationTime',
        },
        {
          title: '业务',
          align: 'center',
          dataIndex: 'business_dictText',
        },
        {
          title: '业务类型',
          align: 'center',
          dataIndex: 'businessType_dictText',
        },
        {
          title: '数量',
          align: 'center',
          dataIndex: 'quantity',
        },
        // {
        //   title: '单位',
        //   align:"center",
        //   dataIndex: 'meUnit_dictText',
        // },
        {
          title: '条码',
          align: 'center',
          dataIndex: 'barcode',
        },
        {
          title: '业务编号',
          align: 'center',
          dataIndex: 'businessCode',
        },
        {
          title: '备注',
          align: 'center',
          dataIndex: 'remark',
        },
      ],
      url: {
        list: '/inventory/bussInventory/queryBussInventoryInoutDetailsByDetailId',
        delete: '/inventory/bussInventory/delete',
        deleteBatch: '/inventory/bussInventory/deleteBatch',
        exportXlsUrl: '/inventory/bussInventory/exportXls',
        importExcelUrl: 'inventory/bussInventory/importExcel',
      },
      dictOptions: {},
      superFieldList: [],
    }
  },
  created() {
    this.loadData()
    this.getSuperFieldList()
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    handleSubmit() {
      this.getGoodsSelectRows()
      this.searchReset(false)
      this.onClearSelected()
      this.close()
    },

    getGoodsSelectRows() {
      let selectedRow = null
      if (this.checkval == 'radio') {
        selectedRow = this.selectionRows[0]
      } else {
        selectedRow = this.selectedRowKeys
      }
      // let selectedRow = this.selectionRows[0];
      //传递选中的数据
      this.$emit('inventoryOk', selectedRow)
    },
    initDictConfig() {},
    close() {
      this.searchReset(false)
      this.visible = false
    },
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'operator', text: '操作人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'operationTime', text: '操作时间', dictCode: '' })
      fieldList.push({ type: 'string', value: 'business', text: '业务', dictCode: 'kc_business' })
      fieldList.push({ type: 'string', value: 'businessType', text: '业务类型', dictCode: 'kc_business_type' })
      fieldList.push({ type: 'BigDecimal', value: 'quantity', text: '数量', dictCode: '' })
      fieldList.push({ type: 'string', value: 'meUnit', text: '单位', dictCode: 'ji_unit' })
      fieldList.push({ type: 'string', value: 'barcode', text: '条码', dictCode: '' })
      fieldList.push({ type: 'string', value: 'businessCode', text: '业务编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'remark', text: '备注', dictCode: '' })
      this.superFieldList = fieldList
    },
    loadData(arg) {
      if (!this.url.list) {
        this.$message.error('请设置url.list属性!')
        return
      }
      //加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1
      }
      var params = this.getQueryParams() //查询条件
      params.id = this.detailId

      console.log('-----------------------------------------')
      console.log(params)
      this.loading = true
      getAction(this.url.list, params)
        .then((res) => {
          if (res.success) {
            this.circleColors = []
            //update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
            this.dataSource = res.result.records || res.result
            console.log(this.dataSource)
            console.log(this.dataSource.length)

            for (let index = 0; index < this.dataSource.length; index++) {
              console.log(index)
              if (this.dataSource[index].business == '1') {
                this.circleColors.push('#CCCCFF')
              } else {
                this.circleColors.push('#FF8888	')
              }
            }
            if (res.result.total) {
              this.ipagination.total = res.result.total
            } else {
              this.ipagination.total = 0
            }
            //update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          } else {
            this.$message.warning(res.message)
          }
        })
        .finally(() => {
          this.loading = false
        })
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>